//
//  FilterBoxDemoViewController.swift
//  ZZUIDemo
//
//  Created by 张文晏 on 2018/11/12.
//  Copyright © 2018 Newcoretech. All rights reserved.
//

import UIKit
import ZZUI

class FilterBoxDemoViewController: UIViewController {
    typealias FilterBoxIdNameItem = NCFilterBox.IdNameItem
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = .white
        
        let box = NCFilterBox.init(owner: self)
        
        let table1 = NCFilterTableView.init()
        table1.selectedClosure = { (items, date) in
            guard !items.isEmpty || date != nil else { return }
            print("items: \(items)")
            if let dt = date {
                print("date: \(dt)")
            }
        }
        
        table1.set(items: [FilterBoxIdNameItem(id: 11 , name: "全部"),FilterBoxIdNameItem(id: 12 , name: "12")])
        table1.isShowTimeView = false
        table1.isShowBottomView = false
        table1.isShowSearchHeader = true
        table1.search { (text) in
            if let str = text {
                print(str)
            }
        }
        let item1 = NCFilterBox.FilterBoxSingleItem.init(button: NCFilterTabButton.init(name: "item1"), table: table1)
        
        let table2 = NCFilterTableView.init()
        table2.selectedClosure = { (items, date) in
            guard !items.isEmpty || date != nil else { return }
            print("items: \(items)")
            if let dt = date {
                print("date: \(dt)")
            }
        }
        table2.set(items: [FilterBoxIdNameItem(id: 21 , name: "21"),FilterBoxIdNameItem(id: 22 , name: "22"),FilterBoxIdNameItem(id: 23 , name: "23"),FilterBoxIdNameItem(id: 24 , name: "24")])
        table2.set(startDate: Date(), endDate: Date())
        table2.selectedDateClosure = { date in
            NCCalendar.showSequenceMode(selectedDates: (date?.0, date?.1), finishClosure: { start, end in
                table2.set(startDate: start, endDate: end)
            })
        }
        let item2 = NCFilterBox.FilterBoxSingleItem.init(button: NCFilterTabButton.init(name: "item2"), table: table2, multiSelection: true)
        
        let table3 = NCFilterCollectionView.init()
        table3.selectedClosure = { sectionItems in
            print(sectionItems)
        }
        table3.set(items: [[FilterBoxIdNameItem(id: 11 , name: "11"),FilterBoxIdNameItem(id:12 , name: "12"),FilterBoxIdNameItem(id: 13 , name: "13"),FilterBoxIdNameItem(id: 14 , name: "14")],
                           [FilterBoxIdNameItem(id: 21 , name: "21"),FilterBoxIdNameItem(id: 22 , name: "22"),FilterBoxIdNameItem(id: 23 , name: "23"),FilterBoxIdNameItem(id: 24 , name: "24")],
                           [FilterBoxIdNameItem(id: 31 , name: "31"),FilterBoxIdNameItem(id: 32 , name: "32"),FilterBoxIdNameItem(id: 33 , name: "33"),FilterBoxIdNameItem(id: 34 , name: "34")]])
        table3.set(sectionNames: ["s1","s2","s3"])
        let item3 = NCFilterBox.FilterBoxSingleItem.init(button: NCFilterTabButton.init(name: "item3"), table: table3, multiSelection: false)
        
        let table4 = NCSecondaryFilterTableView.init()
        table4.selectedClosure = { sectionItems in
            print(sectionItems)
        }
        table4.set(items: [[FilterBoxIdNameItem(id: 11 , name: "11"),FilterBoxIdNameItem(id:12 , name: "12"),FilterBoxIdNameItem(id: 13 , name: "13"),FilterBoxIdNameItem(id: 14 , name: "14")],
                           [FilterBoxIdNameItem(id: 21 , name: "21"),FilterBoxIdNameItem(id: 22 , name: "22"),FilterBoxIdNameItem(id: 23 , name: "23"),FilterBoxIdNameItem(id: 24 , name: "24")],
                           [FilterBoxIdNameItem(id: 31 , name: "31"),FilterBoxIdNameItem(id: 32 , name: "32"),FilterBoxIdNameItem(id: 33 , name: "33"),FilterBoxIdNameItem(id: 34 , name: "34")]])
        table4.set(sectionNames: ["s1","s2","s3"])
        table4.isShowSearchHeader = true
        table4.search { (text) in
            if let str = text {
                print(str)
            }
        }
        let item4 = NCFilterBox.FilterBoxSingleItem.init(button: NCFilterTabButton.init(name: "item4"), table: table4, multiSelection: false)
        
        box.set(items: [item1,item2,item3,item4])
        box.tabButtonContainer.frame = CGRect.init(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 44)
        self.view.addSubview(box.tabButtonContainer)
    }
    
    
}
